home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / ggraph / legend.c < prev    next >
C/C++ Source or Header  |  1989-07-12  |  4KB  |  117 lines

  1. #include <stdio.h>
  2. #include <errno.h>
  3. #include <strings.h>
  4. #include <math.h>
  5. #include "ggraph.h"
  6. #include "ggraphdefs.h"
  7.  
  8. /****************************************************************
  9.  *                                *
  10.  *    drawlegend - draw a legend                *
  11.  *                                *
  12.  ****************************************************************/
  13. drawlegend()
  14. {
  15.     register int i;
  16.     float legendlx, legendly;
  17.     int legend_line_len;
  18.  
  19.     if(legendbox)
  20.       drawlbox();
  21.     legendlx = cg.lframe.frame1x + 10.0;
  22.     legendly = cg.lframe.frame1y+10.0;
  23.     for (curline = 0; ((curline != cg.maxlines) && (cl != NULL)); ++curline)
  24.       if(cl->lonoff){
  25.         drawctext(legendlx+10.0, legendly, cl->llelabel.t_font,
  26.       cl->llelabel.t_size, cl->llelabel.t_text, BOTLEFT_TEXT);
  27.     legend_line_len = xcharsz[cl->llelabel.t_size] * 
  28.       strlen(cl->llelabel.t_text);
  29.     drawline(cl->ltype, legendlx+10.0, legendly-3.0,
  30.       legendlx+legend_line_len+10, legendly-3.0);
  31.     draw_symbol(cl->mtype, legendlx, legendly+5.0);
  32.     legendly = legendly + cg.ylabel.t_size * 15.0 * 0.6;
  33.       }
  34.     if (cg.legend.t_text[0] == NULL)
  35.       strcpy (cg.legend.t_text, "Legend");
  36.     drawctext((cg.lframe.frame1x+cg.lframe.frame3x)/2.0, 
  37.       cg.lframe.frame2y - 3.0, cg.legend.t_font, cg.legend.t_size,
  38.       cg.legend.t_text, TOPCENTER_TEXT);
  39.     return;
  40. }
  41.  
  42. /****************************************************************
  43.  *                                *
  44.  *    drawlbox - draw a frame around the legned        *
  45.  *                                *
  46.  ****************************************************************/
  47. drawlbox()
  48. {
  49.     drawline (cg.lframe.fsize, cg.lframe.frame1x, cg.lframe.frame1y, 
  50.       cg.lframe.frame2x, cg.lframe.frame2y);
  51.     drawline (cg.lframe.fsize, cg.lframe.frame2x, cg.lframe.frame2y, 
  52.       cg.lframe.frame3x, cg.lframe.frame3y);
  53.     drawline (cg.lframe.fsize, cg.lframe.frame3x, cg.lframe.frame3y, 
  54.       cg.lframe.frame4x, cg.lframe.frame4y);
  55.     drawline (cg.lframe.fsize, cg.lframe.frame4x, cg.lframe.frame4y, 
  56.       cg.lframe.frame1x, cg.lframe.frame1y);
  57.     return;
  58. }
  59. /****************************************************************
  60.  *                                *
  61.  *    calc_legend - calculate legend parameters        *
  62.  *                                *
  63.  ****************************************************************/
  64. calc_legend(plotx, ploty)
  65. float *plotx;
  66. float *ploty;
  67. {
  68.     int lelen, maxlelen;
  69.     float leg_width;
  70.  
  71.     maxlelen = 0;
  72.     cg.lframe.fsize = BRUSH_THIN;    /* set brush size */
  73.     for(curline=0;((curline!=MAXLINES) && (cl != NULL));++curline){
  74.       if(cl->lonoff)
  75.     if (cl->llelabel.t_text[0] == NULL)
  76.       strcpy (cl->llelabel.t_text, cl->lname); 
  77.       lelen = strlen (cl->llelabel.t_text); 
  78.       if(maxlelen < lelen)
  79.         maxlelen = lelen;
  80.     }
  81.     if(legendside){
  82. /* should compute length of longest text string and size box */
  83. /* accordingly */
  84.     *plotx = XPLOTMAX - (maxlelen * 10.0) + 20.0;    /* figure out where is starts */
  85.     if(!*ploty)
  86.       *ploty = YSCREENMIN+(ycharsz[cg.ylabel.t_size] * 3.0);
  87.     cg.lframe.frame1x = *plotx+20.0;    /* set legend boundaries */
  88.     cg.lframe.frame2x = cg.lframe.frame1x;
  89.     cg.lframe.frame3x = XSCREENMAX - 5;
  90.     cg.lframe.frame4x = cg.lframe.frame3x;
  91.     cg.lframe.frame1y = cg.yorigin;
  92.     cg.lframe.frame2y = ((cg.maxlines * ycharsz[cg.ylabel.t_size])+
  93.       (3.0*ycharsz[cg.legend.t_size]))+cg.lframe.frame1y;
  94.     cg.lframe.frame3y = cg.lframe.frame2y;
  95.     cg.lframe.frame4y = cg.lframe.frame1y;
  96.     }else{
  97.     *plotx = XPLOTMAX;        /* figure out where is starts */
  98.     if(!*ploty)
  99.       *ploty = YSCREENMIN+((cg.maxlines * ycharsz[cg.ylabel.t_size] *2.0)+
  100.       (4.0*ycharsz[cg.legend.t_size]));
  101.  
  102.     leg_width = (maxlelen * xcharsz[cg.legend.t_size]) + 20.0;    /* figure out where is starts */
  103.  
  104.     cg.lframe.frame1x = ((XSCREENMAX - XSCREENMIN) - leg_width)/2.0
  105.       + XSCREENMIN - 10.0;    /* set legend boundaries */
  106.     cg.lframe.frame2x = cg.lframe.frame1x;
  107.     cg.lframe.frame3x = cg.lframe.frame1x + leg_width + 10.0;
  108.     cg.lframe.frame4x = cg.lframe.frame3x;
  109.     cg.lframe.frame1y = YSCREENMIN+5;
  110.     cg.lframe.frame2y = ((cg.maxlines * ycharsz[cg.ylabel.t_size])+
  111.       (3.0*ycharsz[cg.legend.t_size]))+cg.lframe.frame1y;
  112.     cg.lframe.frame3y = cg.lframe.frame2y;
  113.     cg.lframe.frame4y = cg.lframe.frame1y;
  114.     }
  115.     return;
  116. }
  117.